package com.zzptc.easyshop.servlet;

import com.zzptc.easyshop.dao.UserDao;
import com.zzptc.easyshop.vo.Users;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;

@WebServlet(name = "RegServlet")
public class RegServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        PrintWriter pw = response.getWriter();//创建一个能写的对象
        String username = request.getParameter("userName");   // 获取表单的userName的内容   getParameter
        String pwd = request.getParameter("passWord");
        pw.print(username + "，hello!");        //打印在网页上
        Users users = new Users();
        users.setEu_user_name(username);
        users.setEu_password(pwd);
        UserDao ud = new UserDao();
        boolean i = false;

        i = ud.insert(users);

        if (i) {
            System.out.println("插入成功");
        } else {
            System.out.println("插入失败");
        }

    }
}
